package edu.ustb.aur.chain.interactive;

import edu.ustb.shellchainapi.bean.ChainParam;
import edu.ustb.shellchainapi.shellchain.command.ShellChainCommand;
import edu.ustb.shellchainapi.shellchain.command.ShellChainException;

import java.util.Map;

/**
 * @author SZ
 */
public class ChainInteractiveDao {

    /**
     * 区块链运行命令
     */
    ShellChainCommand shellChainCommand;

    /**
     *
     */
    String hello;

    /**
     * 默认构造函数
     */
    public ChainInteractiveDao() {
        try {
            this.hello = "";
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 带参构造函数
     */
    public ChainInteractiveDao(ChainParam chainParam) {
        this.hello = "";
        shellChainCommand = new ShellChainCommand(chainParam);
    }

    /**
     * 得到链的信息信息
     *
     * @return issueCommand
     */
    public String getInfo() throws ShellChainException {
        return (String) shellChainCommand.getIssueCommand().getInfo();
    }

    /**
     * 上传自定义交易
     *
     * @param toAddress ，目标地址
     * @param amount ，数量
     * @param attributes ，交易属性
     * @return 交易id
     */
    public String sendCustom(String toAddress, float amount, Map<String,Object> attributes) throws ShellChainException {
        return (String) shellChainCommand.getIssueCommand().sendCustom(toAddress, amount, attributes);
    }

    /**
     * 根据交易id，获取交易内容
     *
     * @param txId 交易id
     * @return 交易内容
     */
    public String getRaw(String txId) throws ShellChainException{
//        return (String) shellChainCommand.getIssueCommand().getRawTransaction(txId);
        return (String) shellChainCommand.getIssueCommand().getInfo();
    }
}

